package com.lmy.demo0.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

import com.lmy.demo0.service.INeedService;
import com.lmy.demo0.entity.Need;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lmy
 * @since 2022-08-15
 */
@RestController
@RequestMapping("/need")
public class NeedController {

    @Resource
    private INeedService needService;

            // 新增或者更新
            @PostMapping
            public boolean save(@RequestBody Need need) {
                    return needService.saveOrUpdate(need);
        }

            @DeleteMapping("/{id}")
            public Boolean delete(@PathVariable Integer id) {
                    return needService.removeById(id);
                    }

            @PostMapping("/del/batch")
            public boolean deleteBatch(@RequestBody List<Integer> ids) {
                    return needService.removeByIds(ids);
                    }

            @GetMapping
            public List<Need> findAll() {
                    return needService.list();
                    }

            @GetMapping("/{id}")
            public Need findOne(@PathVariable Integer id) {
                    return needService.getById(id);
                    }

        @GetMapping("/page")
        public Page<Need> findPage(@RequestParam Integer pageNum,
                                   @RequestParam String name,@RequestParam Integer pageSize) {
                QueryWrapper<Need> queryWrapper = new QueryWrapper<>();
                queryWrapper.orderByDesc("id");
                queryWrapper.like("name", name);
                return needService.page(new Page<>(pageNum, pageSize), queryWrapper);

}
        }

